import { GraphData } from './type'
import G6 from '@antv/g6'

class Chart {
  graph: any;

  constructor(config) {
    this.graph = new G6.Graph({
      ...config,
      layout: {
        type: 'force',
        center: [ config.width / 2, config.height / 2 ],
        nodeSize: 20,
        linkDistance: 240,
        nodeStrength: -200,
      },
      modes: {
        default: ['drag-canvas', 'drag-node'],
      },
      defaultEdge: {
        autoRotate: true,
        style: {
          background: {
            fill: '#ffffff',
            stroke: '#000000',
            padding: [2, 2, 2, 2],
            radius: 2,
          },
        },
      }
    })
  }

  data(data: GraphData) {
    G6.Util.processParallelEdges(data.edges);
    this.graph.data(data)
  }

  render() {
    this.graph.render()
  } 
  // graph.data(toGraphData(data))
  // graph.render()
}

export {
    Chart
}  